/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 11:17:16 AM
 * To change this template use File | Settings | File Templates.
 */
import org.jdom.Element;

// Referenced classes of package dk.brics.dsd:
//            Boolexp, Schema, Context

class ElementBoolexp extends Boolexp
{

    ElementBoolexp(Element element, Schema schema)
    {
        name = element.getAttributeValue("name");
        if(name != null)
        {
            name_local = Schema.pnameLocal(name);
            name_uri = Schema.penameURI(name, element);
        }
    }

    byte evaluate(Context context)
    {
        return (byte) (name != null && !Schema.matchPEname(name_local, name_uri, context.e.getName(), context.e.getNamespaceURI()) ? 2 : 1);
    }

    boolean isMentioned(Context context)
    {
        return evaluate(context) == 1;
    }

    public Element toXML(Context context)
    {
        Element element = new Element("element", "http://www.brics.dk/DSD/2.0");
        if(name != null)
            Schema.addPname(element, name, name_uri);
        return element;
    }

    String name;
    String name_local;
    String name_uri;
}
